global Fval;

%load data;
R = 750;
S = num(1:R); %in-sample -> for calculate first param 
Model.Data = S;


% OPTION
if ~isfield(Model, 'MatlabDisp'), Model.MatlabDisp = 'off'; end;
options = optimset('LargeScale', 'off', 'MaxIter', 10000, 'MaxFunEvals', 10000, 'Display', Model.MatlabDisp, 'TolFun', 1e-8, 'TolX', 1e-7, 'TolCon', 1e-7); 
Model.pdf  = 'norm';

Name = 'S_CIR';
ParamsInit = [0.1;0.1;0.1];


FvalPrev = Fval;
Model.Name = Name(3:end);
Model.predictDay = 0;
Exitflag = 0;  Count = 0; MaxCount = 5;
Param = ParamsInit;
fprintf('Estimate %d params from model %s',length(ParamsInit), Model.Name);

while ~Exitflag && Count < MaxCount
    fprintf('.');
    [Param, Fval, Exitflag] =  fminsearch(@(Params) -sum(oneFactorModel (Params, Model)), Param, options);
    Count = Count + 1;
end

if(Exitflag)


Model.predictDay = 180;
outData = num(R+1:N);
x = oneFactorModel (Param, Model);
tempM = [x(30);x(60);x(90);x(180)] - outData([30,60,90,180])
end


% for i = 1 : (N-R) 
%     Model.data = num(i+1:R+i);
%     
% end